/* eslint valid-jsdoc: "off" */

'use strict';

const { view } = require("./plugin");

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1626421796191_6387';

  // add your middleware config here
  config.middleware = ["auth","errorHandler"];

  // 错误捕获
  config.errorHandler = {
    match:'/api'
  }

  // 安全检查
  config.security = {
    csrf:{
      ignore:(ctx)=>{
        // console.log(ctx)
        return true
      }
    }
  }

  config.validate = {
    convert:true,             // 对参数可以使用convertType规则进行类型转换
    // validateRoot: false,   // 限制被验证值必须是一个对象。
    widelyUndefined: true     //空字符串，NaN,null 这些转成 undefined
  }

  // view
  config.view = {
    defaultViewEngine: 'nunjucks',
    defaultExtension:'.html',
    mapping: {
      '.html': 'nunjucks',
    },
  }

  // 语言配置
  config.i18n = {
    defaultLocale:'zh-CN'
  }

  // sequlize
  config.sequelize = {
    dialect: 'mysql',
    host: '127.0.0.1',
    port: 3306,
    database: 'yzq_development',
    username:'root',
    password:'root'
  }

  //json web token
  config.jwt = {
    secret:'123456'
  }

  config.io = {
    init:{},
    namespace:{
      '/': {
        connectionMiddleware: [],
        packetMiddleware: [],
      },
      '/example': {
        connectionMiddleware: [],
        packetMiddleware: [],
      },
    }
  }

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  return {
    ...config,
    ...userConfig,
  };
};
